package avicit.bdp.dds.common.utils;

import avicit.bdp.common.utils.ConfigUtils;
import avicit.bdp.core.constant.Constants;
import avicit.bdp.dds.dispatch.enums.ResUploadType;
import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.UserGroupInformation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URL;

/**
 * common utils
 */
public class CommonUtils {
  private static final Logger logger = LoggerFactory.getLogger(CommonUtils.class);

  private CommonUtils() {
    throw new IllegalStateException("CommonUtils class");
  }

  /**
   * @return get the path of system environment variables
   */
  public static String getSystemEnvPath() {
    String envPath = ConfigUtils.getInstance().getString(avicit.bdp.dds.common.Constants.DOLPHINSCHEDULER_ENV_PATH);
    if (StringUtils.isEmpty(envPath)) {
      URL envDefaultPath = CommonUtils.class.getClassLoader().getResource(avicit.bdp.dds.common.Constants.ENV_PATH);

      if (envDefaultPath != null){
        envPath = envDefaultPath.getPath();
        logger.debug("env path :{}", envPath);
      }else{
        if (OSUtils.isWindows()) {
          envPath = null;
        }else{
          envPath =  "/etc/profile";
        }

      }
    }

    return envPath;
  }

  /**
   *
   * @return is develop mode
   */
  public static boolean isDevelopMode() {
    return ConfigUtils.getInstance().getBoolean(avicit.bdp.dds.common.Constants.DEVELOPMENT_STATE, true);
  }

}
